$(document).ready(function () {
        $("nav li").click(function () {
            var $this = $(this);
            // 给每个点击的对象添加序列号
            index = $this.index();
            // 排他思想  siblings() 返回被选元素的所有的同胞兄弟
            $this.addClass("active").siblings().removeClass("active");
            $(".all_product .main").eq(index).addClass("selected").siblings().removeClass("selected");
        });
    
  $.ajax({
      url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=0",
      type:"get",
      dataType:"json",
      success:function(res){
        //   console.log(res);
          
          var htmlStr=template("allgoodTep",res);
          console.log(htmlStr);
          
          $(".all ul").html(htmlStr)
      }
  })
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=1",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("hotsaleTep", res);
        console.log(htmlStr);

        $(".hot_sale ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=2",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("nineTep", res);
        console.log(htmlStr);

        $(".nine_yuan_mail ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=3",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("nineteenTep", res);
        console.log(htmlStr);

        $(".nineteen_yuan_mial ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=4",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("digitalTep", res);
        console.log(htmlStr);

        $(".digital ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=5",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("familyTep", res);
        console.log(htmlStr);

        $(".family ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=6",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("foodTep", res);
        console.log(htmlStr);

        $(".food ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=7",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("man_clothTep", res);
        console.log(htmlStr);

        $(".man_cloth ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=8",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("women_clothTep", res);
        console.log(htmlStr);

        $(".women_cloth ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=9",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("shoesTep", res);
        console.log(htmlStr);

        $(".shoes ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=10",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("wentiTep", res);
        console.log(htmlStr);

        $(".wenti ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=11",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("wentiTep", res);
        console.log(htmlStr);

        $(".wenti ul").html(htmlStr)
    }
})
$.ajax({
    url: "http://193.112.55.79:9090/api/getbaicaijiaproduct?titleid=12",
    type: "get",
    dataType: "json",
    success: function (res) {
        // console.log(res);

        var htmlStr = template("mom_sonTep", res);
        console.log(htmlStr);

        $(".mom_son ul").html(htmlStr)
    }
})
});
window.onload = function () {
    // 1.获得要操作的对象
    var headerBar = document.querySelector("header");
    var navBar=document.querySelector("nav");
    // 2.给事件源注册事件
    window.onscroll = function () {
        var scrollTop = scroll().scrollTop;//滚动距离
        if (scrollTop > headerBar.offsetHeight) {
            navBar.className = "fixed";
        } else {
            navBar.className = "static"; // relative  absolute  fixed  static
            // headerBar.paddingtop="100px";
        }
    }

    function scroll() {
        return {
            scrollLeft: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
            scrollTop: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
        }
    }
}

var lis = document.getElementsByClassName('tab');
for (var i = 0; i < lis.length; i++) {
    lis[i].onclick = function () {
        var that = this;
        for (var i = 0; i < lis.length; i++) {
            lis[i].classList.remove('active')
            this.classList.add('active')
        }
    }
}
// 标题滑动导航
$("nav ul").width(($("nav ul").find("li").length) * ($("nav ul").find("li").outerWidth(true)));//ul的长度=li的个数 X li的长度
var myScroll = new IScroll('nav', { scrollX: true, scrollY: false });

window.onload=function () {
    var toTop = document.querySelector("to_top");
    var timeId=null;
    var leader=0;
    var target=0;
    //給事件源注册页面滚动事件
    window.onscroll=function () {
        //获取页面滚动的距离
        leader=scroll().scrollTop;
        //判断
        if(leader>400){
            toTop.style.display="block";
        }else{
            toTop.style.display="none"
        }
    }
        toTop.onclick=function () {
            timeId=setInterval(function () {
                target=0;
                leader=leader+(target-leader)/10;
                window.scrollTo(0,leader);
                if(leader==target){
                    clearInterval(timeId);
                    toTop.style.display="none"
                }
            },15)
        }
}
